use crate::app::AppState;
use crate::error::{ApiError, ApiResult};
use axum::response::Html;
use axum::{debug_handler, Router};
use sea_orm::ColIdx;

mod stop;


pub fn create_router() -> Router<AppState> {
    Router::new()
        .route("/", axum::routing::get(index_handler))
        .nest(
            "/api",
            Router::new().nest("/stops", stop::create_router())
                .fallback(async || -> ApiResult<()>{
                    tracing::warn!("Not found");
                    Err::<(), ApiError>(ApiError::NotFound)
                }),
        )
        .method_not_allowed_fallback(async || -> ApiResult<()>{
            tracing::warn!("Method not allowed");
            Err::<(), ApiError>(ApiError::MethodNotAllowed)
        })
}
#[debug_handler]
async fn index_handler() -> ApiResult<Html<String>> {
    let content = r#"<h1>Welcome!</h1>
                   <p>You are logged in.</p>
                   <p><a href="/userinfo">View User Info (from UserInfo endpoint)</a></p>
                   <p><a href="/login">Login Again</a></p>
                   <p><a href="/logout">Logout</a></p>"#;
    Ok(Html(content.to_string()))
}

